<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sistema Contactos </title>
<%@include file="/WEB-INF/jsp/org/contact/main/librerias.jsp" %>
<%@include file="/WEB-INF/jsp/org/contact/contactos/ContactGridPanel.jsp" %>
<%@include file="/WEB-INF/jsp/org/contact/contactos/ContactFormPanel.jsp" %>
</head>
<body>
<script type="text/javascript">

var contactGridPanel;
var contactFormPanel;

Ext.onReady(function(){

	var contactFormWindow;

	contactGridPanel = new Ext.org.contact.ContactGridPanel({
		region: 'center',
		id: 'grid_contacto',
		loadMask: true
	});

	var windowPrincipal = new Ext.Window({
		title: 'Listado de contactos',
		layout: 'border',
		closable: false,
		items: [contactGridPanel]
	});
	windowPrincipal.show();
	windowPrincipal.maximize();

	Ext.getCmp('cbo-buscar').setValue('nombre');
	Ext.getCmp('cbo-buscar').setRawValue('Nombre');

});

function contact_new(){

	contactFormPanel = new Ext.org.contact.ContactFormPanel({
		region: 'center',
		id: 'contact-formPanel'
	});

	contactFormWindow = new Ext.Window({
		title: 'Registro de contactos',
		layout: 'border',
		height: 300,
		width: 580,
		modal: true,
		items: [contactFormPanel],
		tbar: [{
			text: 'Guardar',
			icon: 'images/user_add.png',
			handler: function(){
				if(Ext.getCmp('contact-formPanel').form.isValid()){
					Ext.getCmp('contact-formPanel').form.submit({
						url: 'Contact.htm?action=guardarContacto',
						success: function(form, action){
							Ext.Msg.alert('Info', 'Se guardo satisfactoriamente');
							Ext.getCmp('grid_contacto').store.load();
						},
						failure: function(form, action){
							Ext.Msg.alert('Error', 'Error al guardar, verifique sus datos');
						}
					});
				}else {
					Ext.Msg.alert('Info', 'Hay campos obligatorios vacios');
				}
			}
		}]
	});
	contactFormWindow.show();
	
}

function search(value){
	var filterObj = {
		col: Ext.getCmp('cbo-buscar').getValue(),
		val: value//Ext.getCmp('txt-buscar').getRawValue()
	};
	Ext.getCmp('grid_contacto').store.load({
		params: {
			filter: Ext.util.JSON.encode(filterObj)
		}
	});
}
</script>
</body>
</html>